
<?php defined('_JEXEC') or die('Restricted access'); ?>

<?php
if (!isset($_SESSION['username']) && !isset($_SESSION['usertype']))
    header("location: index.php");
?>

<script language="javascript">
    function new_item(a, b) {
        var i = document.getElementById(b).value;
        document.getElementById(a).insertAdjacentHTML('beforeEnd', "<table cellspacing=5 cellpadding=5><tr><td width=100px>Slab " + i + "</td><td><input name='slab_weight[" + i + "]' type='text' value='' size='6' /></td><td><select name='slab_unit[" + i + "]'><option value='1'>gms</option><option value='2'>kgs</option></select></td><td><input name='slab_local[" + i + "]' type='text' value='' size='6' /></td><td><input name='slab_state[" + i + "]' type='text' value='' size='6' /></td><td><input name='slab_region[" + i + "]' type='text' value='' size='6' /></td><td><input name='slab_rest[" + i + "]' type='text' value='' size='6' /></td><td><input name='slab_zone5[" + i + "]' type='text' value='' size='6' /></td><td><input name='slab_zone6[" + i + "]' type='text' value='' size='6' /></td><td><input name='slab_zone7[" + i + "]' type='text' value='' size='6' /></td><td><input name='slab_zone8[" + i + "]' type='text' value='' size='6' /></td><td><input name='slab_zone9[" + i + "]' type='text' value='' size='6' /></td><td><input name='slab_zone10[" + i + "]' type='text' value='' size='6' /></td><td><input name='slab_zone11[" + i + "]' type='text' value='' size='6' /></td><td><input name='slab_zone12[" + i + "]' type='text' value='' size='6' /></td></tr></table>");
        document.getElementById(b).value = parseInt(i) + 1;
    }
</script>
<?php
if (isset($submit)) {
    switch (trim($submit)) {
        case "Save":
            $sql = "SELECT tbl2.companyname, 
					(CASE 
					WHEN destination_id = '-1' THEN 'All Destination' 
					ELSE (SELECT destination FROM destinations WHERE id = tbl1.destination_id ) 
					END) AS `destinationname` 
					FROM slabs AS `tbl1` INNER JOIN companies as `tbl2` ON tbl1.company_id = tbl2.id where tbl1.company_id = '" . $company_id . "' and tbl1.slab_type = '" . $slab_type . "' and tbl1.slab_for = '" . $slab_for . "' and tbl1.destination_id = '" . $destination_id . "'";
            $result = mysql_query($sql);
            if (mysql_num_rows($result) > 0) {
                $row = mysql_fetch_array($result);
                $arr[] = "<b>" . $slab_type_arr[$slab_type] . "</b> slab for <b>" . $row['companyname'] . "</b> is already exists for <b>" . $slab_for_arr[$slab_for] . "</b> and <b>" . $row['destinationname'] . "</b>";
                unset($count);
                break;
            }

            b($additional_slab_weight, "Enter Additional Weight");
            i($additional_slab_weight, "Additional Weight must be in Number");
            b($additional_slab_local, "Enter Additional Price for Local");
            i($additional_slab_local, "Additional Price for Local must be in Number");
            i($additional_slab_state, "Additional Price for Within State must be in Number");
            b($additional_slab_region, "Enter Additional Price for Within Region");
            i($additional_slab_region, "Additional Price for Within Region must be in Number");
            b($additional_slab_rest, "Enter Additional Price for Rest of India");
            i($additional_slab_rest, "Additional Price for Rest of India must be in Number");
            b($slab_weight[0], "Enter Slab 1 Weight");

            foreach ($slab_weight as $k => $v) {
                if ($slab_weight[$k] != "") {
                    i($slab_weight[$k], "Slab " . ($k + 1) . " Weight must be in Number");
                    b($slab_local[$k], "Enter Slab " . ($k + 1) . " Price for Local");
                    i($slab_local[$k], "Slab " . ($k + 1) . " Price for Local must be in Number");
                    i($slab_state[$k], "Slab " . ($k + 1) . " Price for within state must be in Number");
                    b($slab_region[$k], "Enter Slab " . ($k + 1) . " Price for within region");
                    i($slab_region[$k], "Slab " . ($k + 1) . " Price for within region must be in Number");
                    b($slab_rest[$k], "Enter Slab " . ($k + 1) . " Price for Rest of India");
                    i($slab_rest[$k], "Slab " . ($k + 1) . " Price for Rest of India must be in Number");
                }
            }

            if (count($arr) == 0) {
                $sql = "insert into slabs(company_id,slab_type,slab_for,destination_id,additional_slab_weight,additional_slab_unit,additional_slab_local,additional_slab_state,additional_slab_region,additional_slab_rest,additional_slab_zone5,additional_slab_zone6,additional_slab_zone7,additional_slab_zone8,additional_slab_zone9,additional_slab_zone10,additional_slab_zone11,additional_slab_zone12) values(\"$company_id\",\"$slab_type\",\"$slab_for\",\"$destination_id\",\"$additional_slab_weight\",\"$additional_slab_unit\",\"$additional_slab_local\",\"$additional_slab_state\",\"$additional_slab_region\",\"$additional_slab_rest\",\"$additional_slab_zone5\",\"$additional_slab_zone6\",\"$additional_slab_zone7\",\"$additional_slab_zone8\",\"$additional_slab_zone9\",\"$additional_slab_zone10\",\"$additional_slab_zone11\",\"$additional_slab_zone12\")";
                mysql_query($sql);
                $msg = "Company Slab added succesful";
                $company_id = $slab_type = $slab_for = $destination_id = $additional_slab_weight = $additional_slab_unit = $additional_slab_local = $additional_slab_state = $additional_slab_region = $additional_slab_rest = $additional_slab_zone5 = $additional_slab_zone6 = $additional_slab_zone7 = $additional_slab_zone8 = "";
                $slab_id = mysql_insert_id();
                foreach ($slab_weight as $k => $v) {
                    if ($slab_weight[$k] != "") {
                        $sql = "insert into slabdetails(slab_id,slab_weight,slab_unit,slab_local,slab_state,slab_region,slab_rest,slab_zone5,slab_zone6,slab_zone7,slab_zone8,slab_zone9,slab_zone10,slab_zone11,slab_zone12) values('" . $slab_id . "','" . $slab_weight[$k] . "','" . $slab_unit[$k] . "','" . $slab_local[$k] . "','" . $slab_state[$k] . "','" . $slab_region[$k] . "','" . $slab_rest[$k] . "','" . $slab_zone5[$k] . "','" . $slab_zone6[$k] . "','" . $slab_zone7[$k] . "','" . $slab_zone8[$k] . "','" . $slab_zone9[$k] . "','" . $slab_zone10[$k] . "','" . $slab_zone11[$k] . "','" . $slab_zone12[$k] . "')";
                        mysql_query($sql);
                        $slab_weight[$k] = $slab_unit[$k] = $slab_local[$k] = $slab_state[$k] = $slab_region[$k] = $slab_rest[$k] = $slab_zone5[$k] = $slab_zone6[$k] = $slab_zone7[$k] = $slab_zone8[$k] =  $slab_zone9[$k] =   $slab_zone10[$k] =  $slab_zone11[$k] =   $slab_zone12[$k] = "";
                    }
                }
                unset($count);
            } else {
                unset($count);
            }
            break;
        case "Update":
            if ($step == 2) {
                $sql = "select tbl2.companyname from slabs as `tbl1` INNER JOIN companies as `tbl2` ON tbl1.company_id = tbl2.id where tbl1.company_id = '" . $company_id . "' and tbl1.slab_type = '" . $slab_type . "' and tbl1.slab_for = '" . $slab_for . "' and tbl1.destination_id = '" . $destination_id . "' and tbl1.id <> '" . $id . "'";
                $result = mysql_query($sql);
                if (mysql_num_rows($result) > 0) {
                    $row = mysql_fetch_array($result);
                    $arr[] = "<b>" . $slab_type_arr[$slab_type] . "</b> slab for <b>" . $row['companyname'] . "</b> is already exists for <b>" . $slab_for_arr[$slab_for];
                    unset($count);
                    break;
                }

                b($additional_slab_weight, "Enter Additional Weight");
                i($additional_slab_weight, "Additional Weight must be in Number");
                b($additional_slab_local, "Enter Additional Price for Local");
                i($additional_slab_local, "Additional Price for Local must be in Number");
                i($additional_slab_state, "Additional Price for Within State must be in Number");
                b($additional_slab_region, "Enter Additional Price for Within Region");
                i($additional_slab_region, "Additional Price for Within Region must be in Number");
                b($additional_slab_rest, "Enter Additional Price for Rest of India");
                i($additional_slab_rest, "Additional Price for Rest of India must be in Number");
                b($slab_weight[0], "Enter Slab 1 Weight");

                foreach ($slab_weight as $k => $v) {
                    if ($slab_weight[$k] != "") {
                        i($slab_weight[$k], "Slab " . ($k + 1) . " Weight must be in Number");
                        b($slab_local[$k], "Enter Slab " . ($k + 1) . " Price for Local");
                        i($slab_local[$k], "Slab " . ($k + 1) . " Price for Local must be in Number");
                        i($slab_state[$k], "Slab " . ($k + 1) . " Price for within state must be in Number");
                        b($slab_region[$k], "Enter Slab " . ($k + 1) . " Price for within region");
                        i($slab_region[$k], "Slab " . ($k + 1) . " Price for within region must be in Number");
                        b($slab_rest[$k], "Enter Slab " . ($k + 1) . " Price for Rest of India");
                        i($slab_rest[$k], "Slab " . ($k + 1) . " Price for Rest of India must be in Number");
                    }
                }
                if (count($arr) == 0) {
                    $sql = "update slabs set company_id=\"$company_id\", slab_type=\"$slab_type\", slab_for=\"$slab_for\", destination_id=\"$destination_id\", additional_slab_weight=\"$additional_slab_weight\", additional_slab_unit=\"$additional_slab_unit\", additional_slab_local=\"$additional_slab_local\", additional_slab_state=\"$additional_slab_state\", additional_slab_region=\"$additional_slab_region\", additional_slab_rest=\"$additional_slab_rest\", additional_slab_zone5=\"$additional_slab_zone5\", additional_slab_zone6=\"$additional_slab_zone6\", additional_slab_zone7=\"$additional_slab_zone7\", additional_slab_zone8=\"$additional_slab_zone8\", additional_slab_zone9=\"$additional_slab_zone9\", additional_slab_zone10=\"$additional_slab_zone10\", additional_slab_zone11=\"$additional_slab_zone11\", additional_slab_zone12=\"$additional_slab_zone12\" where id = '$id'";
                    mysql_query($sql);
                    $msg = "Company Slab updated succesful";
                    $company_id = $slab_type = $slab_for = $destination_id = $additional_slab_weight = $additional_slab_unit = $additional_slab_local = $additional_slab_state = $additional_slab_region = $additional_slab_rest = $additional_slab_zone5 = $additional_slab_zone6 = $additional_slab_zone7 = $additional_slab_zone8 = "";

                    $slab_id = $id;
                    $sql = "delete from slabdetails where slab_id = '$slab_id'";
                    mysql_query($sql);

                    foreach ($slab_weight as $k => $v) {
                        if ($slab_weight[$k] != "") {
                            $sql = "insert into slabdetails(slab_id,slab_weight,slab_unit,slab_local,slab_state,slab_region,slab_rest,slab_zone5,slab_zone6,slab_zone7,slab_zone8,slab_zone9,slab_zone10,slab_zone11,slab_zone12) values('" . $slab_id . "','" . $slab_weight[$k] . "','" . $slab_unit[$k] . "','" . $slab_local[$k] . "','" . $slab_state[$k] . "','" . $slab_region[$k] . "','" . $slab_rest[$k] . "','" . $slab_zone5[$k] . "','" . $slab_zone6[$k] . "','" . $slab_zone7[$k] . "','" . $slab_zone8[$k] . "','" . $slab_zone9[$k] . "','" . $slab_zone10[$k] . "','" . $slab_zone11[$k] . "','" . $slab_zone12[$k] . "')";
                            mysql_query($sql);
                            $slab_weight[$k] = $slab_unit[$k] = $slab_local[$k] = $slab_state[$k] = $slab_region[$k] = $slab_rest[$k] = $slab_zone5[$k] = $slab_zone6[$k] = $slab_zone7[$k] = $slab_zone8[$k] == $slab_zone9[$k] = $slab_zone10[$k] = $slab_zone11[$k] = $slab_zone12[$k] = "";
                        }
                    }
                    unset($count);
                } else {
                    $btval = "     Update     ";
                }
            } else if (isset($eid)) {
                $sql = "select * from slabs where id = '$eid'";
                $result = mysql_query($sql);
                $row = mysql_fetch_array($result);
                $id = $row['id'];
                $company_id = $row['company_id'];
                $slab_type = $row['slab_type'];
                $slab_for = $row['slab_for'];
                $destination_id = $row['destination_id'];
                $additional_slab_weight = $row['additional_slab_weight'];
                $additional_slab_unit = $row['additional_slab_unit'];
                $additional_slab_local = $row['additional_slab_local'];
                $additional_slab_state = $row['additional_slab_state'];
                $additional_slab_region = $row['additional_slab_region'];
                $additional_slab_rest = $row['additional_slab_rest'];
                $additional_slab_zone5 = $row['additional_slab_zone5'];
                $additional_slab_zone6 = $row['additional_slab_zone6'];
                $additional_slab_zone7 = $row['additional_slab_zone7'];
                $additional_slab_zone8 = $row['additional_slab_zone8'];
                $additional_slab_zone9 = $row['additional_slab_zone9'];
                $additional_slab_zone10 = $row['additional_slab_zone10'];
                $additional_slab_zone11 = $row['additional_slab_zone11'];
                $additional_slab_zone12 = $row['additional_slab_zone12'];

                $sql = "select * from slabdetails where slab_id = '$eid'";
                $result = mysql_query($sql);
                $count = 0;
                while ($row = mysql_fetch_array($result)) {
                    $slab_weight[] = $row['slab_weight'];
                    $slab_unit[] = $row['slab_unit'];
                    $slab_local[] = $row['slab_local'];
                    $slab_state[] = $row['slab_state'];
                    $slab_region[] = $row['slab_region'];
                    $slab_rest[] = $row['slab_rest'];
                    $slab_zone5[] = $row['slab_zone5'];
                    $slab_zone6[] = $row['slab_zone6'];
                    $slab_zone7[] = $row['slab_zone7'];
                    $slab_zone8[] = $row['slab_zone8'];
                    $slab_zone9[] = $row['slab_zone9'];
                    $slab_zone10[] = $row['slab_zone10'];
                    $slab_zone11[] = $row['slab_zone11'];
                    $slab_zone12[] = $row['slab_zone12'];

                    $count++;
                }
                $step = 2;
                $btval = "     Update     ";
            }
            break;
        case "Delete":
            $sql = "delete from slabs where id = '$eid'";
            mysql_query($sql);
            $msg = "Company Slab delete succesful";

            $sql = "delete from slabdetails where slab_id = '$eid'";
            mysql_query($sql);

            break;
    }
}

if (!isset($btval))
    $btval = "     Save     ";



$sql = "select id, companyname from companies where status = 1 order by companyname";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
    $company_arr[$row['id']] = $row['companyname'];
}

$sql = "select id, destination from destinations where status = 1 order by destination";
$result = mysql_query($sql);
$destination_arr[-1] = "All Destinations";
while ($row = mysql_fetch_array($result)) {
    $destination_arr[$row['id']] = $row['destination'];
}

if (!isset($count))
    $count = 2;
?>

<div id="title">Company Slab Management</div>

<form name="slab-form" method="post" action="">
    <table border="0" cellspacing="3" cellpadding="3" align="center">
        <tr><td><?php se(); ?></td></tr>
        <tr>
            <td>
                <table cellspacing="3" cellpadding="3">
                    <tr>
                        <td>	
                            Company Name:
                        </td>
                        <td>	
                            <select name="company_id">
<?php
sopt($company_arr, $company_id)
?>
                            </select>
                        </td>
                    </tr>	
                    <tr>
                        <td>	
                            Slab Type:
                        </td>
                        <td>	
                            <select name="slab_type">
<?php
sopt($slab_type_arr, $slab_type)
?>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>	
                            <!-- Slab For: -->
                        </td>
                        <td>	
                            <select name="slab_for" style="display: none;">
<?php
sopt($slab_for_arr, $slab_for)
?>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>	
                            Destination:
                        </td>
                        <td>	
                            <select name="destination_id">
<?php
sopt($destination_arr, $destination_id);
?>
                            </select>
                        </td>
                    </tr>
                </table>		
            </td>
        </tr>
        <tr>
            <td>
                <table cellspacing=5 cellpadding=5>
                    <tr style='background: #CECECE; color: #333333;'>
                        <th  style="width:100px">Slab</th>
                        <th style="width:76px">Weight</th>
                        <th style="width:54px">Unit</th>
<?php
foreach ($destination_type_arr as $val) {
    echo '<th style="width:70px">' . $val . '</th>';
}
?>

                    </tr>   
                    
                </table>
<?php
for ($i = 0; $i < $count; $i++) {
    if($i>=2 )
                break;
    ?>
<table cellspacing=5 cellpadding="5" id="weight<?php echo ($i + 1) ?>" <?php if($slab_weight[$i]!=0){ ?> style="display: block" <?php } ?> >
                        <tr>
                            <td width=100px>Weight <?php echo ($i + 1) ?></td>
                            <td><input name="slab_weight[<?php echo $i ?>]" type="text" value="<?php echo $slab_weight[$i]?$slab_weight[$i] : '0' ?>" size='6' /></td>
                            <td>
                                <select name="slab_unit[<?php echo $i ?>]"><option value="1">gms</option>
                                    <?php
                                    #sopt($weight_unit_arr, $slab_unit[$i])
                                    ?>
                                </select>
                            </td>
                            <td><input name="slab_local[<?php echo $i ?>]" type="text" value="<?php echo  $slab_local[$i]?$slab_local[$i] : '0'?>" size='6' /></td>
                            <td><input name="slab_state[<?php echo $i ?>]" type="text" value="<?php echo $slab_state[$i]?$slab_state[$i] : '0'?>" size='6' /></td>
                            <td><input name="slab_region[<?php echo $i ?>]" type="text" value="<?php echo  $slab_region[$i]?$slab_region[$i] : '0'?>" size='6' /></td>
                            <td><input name="slab_rest[<?php echo $i ?>]" type="text" value="<?php echo  $slab_rest[$i]?$slab_rest[$i] : '0'?>" size='6' /></td>
                            <td><input name="slab_zone5[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone5[$i]?$slab_zone5[$i] : '0'?>" size='6' /></td>
                            <td><input name="slab_zone6[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone6[$i]?$slab_zone6[$i] : '0' ?>" size='6' /></td>
                            <td><input name="slab_zone7[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone7[$i]?$slab_zone7[$i] : '0' ?>" size='6' /></td>
                            <td><input name="slab_zone8[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone8[$i]?$slab_zone8[$i] : '0' ?>" size='6' /></td>
                            <td><input name="slab_zone9[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone9[$i] ?$slab_zone9[$i] : '0'?>" size='6' /></td>
                            <td><input name="slab_zone10[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone10[$i]?$slab_zone10[$i] : '0' ?>" size='6' /></td>
                            <td><input name="slab_zone11[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone11[$i]?$slab_zone11[$i] : '0' ?>" size='6' /></td>
                            <td><input name="slab_zone12[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone12[$i]?$slab_zone12[$i] : '0' ?>" size='6' /></td>
                        </tr>
                    </table>
    <?php
}
?>
                <div id="add_item"></div>
                <input type="hidden" name="count" id="count" value="<?php echo ($i + 1) ?>">
                <a href="javascript:void(0)" id="weightmore">Add More Slab</a>
                <!-- <a href="javascript:void(0)" onclick="new_item('add_item', 'count')">Add More Slabs</a>  -->
                
                <table cellspacing=5 cellpadding=5>
                    <tr>
                        <td width="100px">Additional Slab</td>
                        <td><input name="additional_slab_weight" type="text" value="<?php echo $additional_slab_weight ?>" size='6' /></td>
                        <td>
                            <select name="additional_slab_unit"><option value="1">gms</option></select>
                        </td>
                        <td><input name="additional_slab_local" type="text" value="<?php echo $additional_slab_local ?>" size='6' /></td>
                        <td><input name="additional_slab_state" type="text" value="<?php echo $additional_slab_state ?>" size='6' /></td>
                        <td><input name="additional_slab_region" type="text" value="<?php echo $additional_slab_region ?>" size='6' /></td>
                        <td><input name="additional_slab_rest" type="text" value="<?php echo $additional_slab_rest ?>" size='6' /></td>
                        <td><input name="additional_slab_zone5" type="text" value="<?php echo $additional_slab_zone5 ?>" size='6' /></td>
                        <td><input name="additional_slab_zone6" type="text" value="<?php echo $additional_slab_zone6 ?>" size='6' /></td>
                        <td><input name="additional_slab_zone7" type="text" value="<?php echo $additional_slab_zone7 ?>" size='6' /></td>
                        <td><input name="additional_slab_zone8" type="text" value="<?php echo $additional_slab_zone8 ?>" size='6' /></td>
                        <td><input name="additional_slab_zone9" type="text" value="<?php echo $additional_slab_zone9 ?>" size='6' /></td>
                        <td><input name="additional_slab_zone10" type="text" value="<?php echo $additional_slab_zone10 ?>" size='6' /></td>
                        <td><input name="additional_slab_zone11" type="text" value="<?php echo $additional_slab_zone11 ?>" size='6' /></td>
                        <td><input name="additional_slab_zone12" type="text" value="<?php echo $additional_slab_zone12 ?>" size='6' /></td>
                    </tr>
                </table>
                <table cellspacing=5 cellpadding=5>
                        <tr>
                            <td width=100px>Weight Above <?php $i=2; ?></td>
                            <td><input name="slab_weight[<?php echo $i ?>]" type="text" value="<?php echo $slab_weight[$i] ?>" size='6' /></td>
                            <td>
                                <select name="slab_unit[<?php echo $i ?>]"><option value="2" selected="">kgs</option></select>
                            </td>
                            <td><input name="slab_local[<?php echo $i ?>]" type="text" value="<?php echo $slab_local[$i] ?>" size='6' /></td>
                            <td><input name="slab_state[<?php echo $i ?>]" type="text" value="<?php echo $slab_state[$i] ?>" size='6' /></td>
                            <td><input name="slab_region[<?php echo $i ?>]" type="text" value="<?php echo $slab_region[$i] ?>" size='6' /></td>
                            <td><input name="slab_rest[<?php echo $i ?>]" type="text" value="<?php echo $slab_rest[$i] ?>" size='6' /></td>
                            <td><input name="slab_zone5[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone5[$i] ?>" size='6' /></td>
                            <td><input name="slab_zone6[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone6[$i] ?>" size='6' /></td>
                            <td><input name="slab_zone7[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone7[$i] ?>" size='6' /></td>
                            <td><input name="slab_zone8[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone8[$i] ?>" size='6' /></td>
                            <td><input name="slab_zone9[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone9[$i] ?>" size='6' /></td>
                            <td><input name="slab_zone10[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone10[$i] ?>" size='6' /></td>
                            <td><input name="slab_zone11[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone11[$i] ?>" size='6' /></td>
                            <td><input name="slab_zone12[<?php echo $i ?>]" type="text" value="<?php echo $slab_zone12[$i] ?>" size='6' /></td>
                        </tr>
                    </table>
            </td>
        </tr>
        <tr>
            <td align="center">
                <input type=hidden name=id value="<?php echo $id ?>" />
                <input type=hidden name=step value="<?php echo $step ?>" />
                <input type="submit" name="submit" value="<?php echo $btval ?>" class='button'/>
            </td>
        </tr>	
    </table>
</form>

<script>
    $(function(){
       $('#weightmore').click(function(){
           $('#weight2').show();
           $(this).hide();
       });
    });
</script>
<?php
echo "<hr />";
$table = "slabs";
$cols = "id, (select companyname from companies where id = company_id) as `Company Name`, slab_type, slab_for, destination_id as `Destination`";
$orderby = ($orderby == '') ? "`Company Name`, slab_type, slab_for" : $orderby;
$sort = ($sort == '') ? "asc" : $sort;
$pagelength = 50;
$reparr = array();
foreach ($slab_type_arr as $k => $v) {
    $reparr['slab_type'][$k] = $v;
}
foreach ($slab_for_arr as $k => $v) {
    $reparr['slab_for'][$k] = $v;
}
foreach ($destination_arr as $k => $v) {
    $reparr['Destination'][$k] = $v;
}

gettable("$table", $cols, "$where", "$orderby", "$sort", $pg, "<a href='?eid=\$id&submit=Update' style='text-decoration:none'>Update</a>&nbsp;|&nbsp;<a href=\"?eid=\$id&submit=Delete\" onclick=\"javascript:return confirm('Are you sure you want to Delete?')\" style='text-decoration:none'>Delete</a>", Array("id"), $reparr);
?>